String.prototype.replaceAll = function (s1, s2) {
    return this.replace(new RegExp(s1, "gm"), s2);
};
Ext.define('Ext.ux.NuberFiledFormat', {
    extend: 'Ext.form.field.Number',
    xtype: 'numberFieldFormat',
    negativeText: '该输入项的值不能为负数',
    maxValue: 99999999999999.99,
    valueToRaw: function (value) {
        var me = this,
            decimalSeparator = me.decimalSeparator;
        value = me.parseValue(value);
        value = me.fixPrecision(value);
        value = Ext.isNumber(value) ? value : parseFloat(String(value).replace(decimalSeparator, '.'));
        value = isNaN(value) ? '' : value;
        value = String(value).split('.')[0].replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,') + (String(value).split('.')[1] ? ('.' + String(value).split('.')[1]) : '');
        value = String(value).replace('.', decimalSeparator);
        return value;
    },
    getSubmitValue: function () {
        var me = this,
            value = me.callParent();
        if (!me.submitLocaleSeparator) {
            value = value.replace(me.decimalSeparator, '.');
        }
        value = parseFloat(String(value).replaceAll(",", ""));
        value = isNaN(value) ? null : value;
        return value;
    },
    getErrors: function (value) {
        var newValue=value;
        if (value && value.length > 0) {
            value = parseFloat(String(value).replaceAll(",", ""));
        }
        if(!isNumber(value)){
            value=newValue
        }
        var rawValue = this.getRawValue();
        if (rawValue && rawValue.length > 0) {
            rawValue = parseFloat(String(rawValue).replaceAll(",", ""));
        }
        value = arguments.length > 0 ? value : this.processRawValue(rawValue);
        var me = this,
              // errors = me.callParent([value]),//errors提示会重复，直接定义为[]，不会重复
              errors =[],
            format = Ext.String.format,
            num;
        if (value.length < 1) { // if it's blank and textfield didn't flag it then it's valid
            return errors;
        }
        value = String(value).replace(me.decimalSeparator, '.');
        if (isNaN(value)) {
            errors.push(format(me.nanText, value));
        }
        num = me.parseValue(value);
        if (me.minValue === 0 && num < 0) {
            errors.push(this.negativeText);
        }
        else if (num < me.minValue) {
            errors.push(format(me.minText, me.minValue));
        }
        if (num > me.maxValue) {
            errors.push(format(me.maxText, me.maxValue));
        }
        return errors;
    },
    fixPrecision: function (value) {
        var me = this,
            nan = isNaN(value),
            precision = me.decimalPrecision;
        if (nan || !value) {
            return nan ? '' : value;
        } else if (!me.allowDecimals || precision <= 0) {
            precision = 0;
        }
        return parseFloat(Ext.Number.toFixed(parseFloat(value), precision));
    },
    parseValue: function (value) {
        value = String(value).replaceAll(',', '');
        value = parseFloat(String(value).replace(this.decimalSeparator, '.'));
        return isNaN(value) ? null : value;
    }
});
function isNumber(num) {
    return typeof num === 'number' && !isNaN(num)
}
